package com.ninth_group.dao.Impl;

import com.ninth_group.dao.PCDao;
import com.ninth_group.utils.HiveUtil;
import com.ninth_group.vo.ProvinceCitiesVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;

@Repository
public class PCDaoImpl implements PCDao {
    @Autowired
    private HiveUtil hiveUtil;

    private static final String QUERY_SQL =
            "select * from city_base_info where province = ?";
    /**
     * 获取城市天气信息
     *
     * @param pName 省份名称
     * @return List<ProvinceCitiesVO>
     */
    @Override
    public List<ProvinceCitiesVO> getPCWeatherInfo(String pName) {
        return hiveUtil.executeQuery(QUERY_SQL, s -> {
            try {
                return ProvinceCitiesVO.mapRow(s);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }, pName);
    }
}
